SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[paActualizarFechaPresentacion] AS

SET NOCOUNT ON

DECLARE @error INT

SET @error = 0

BEGIN TRANSACTION
	--Busco todas las tablas que tienen el campo : Fechapresentacion
		DECLARE X CURSOR FORWARD_ONLY FOR
		select a.name from sysobjects a join syscolumns b on b.id=a.id
		where a.type = 'u'  and b.name like '%Fechapresentacion%'
		order by a.name



OPEN X

DECLARE @Nombre varchar(100)
declare @temp as varchar(1000)

FETCH NEXT FROM X INTO @Nombre

WHILE @@FETCH_STATUS = 0 BEGIN

		SELECT @temp = ' UPDATE ' +  @nombre + ' SET Fechapresentacion =  convert(datetime,' +char(39)+rtrim('31 / 12 / 2004') +char(39)+ ') where agente in (54475,55908,62051,55904,56346,55273,53903,53091,53230,54966)'
		print @temp
--		EXEC(@temp)
		IF @@error <> 0 BEGIN
			SET @error = @@error
			GOTO Salir
		END

		FETCH NEXT FROM X INTO @Nombre

END

CLOSE X
DEALLOCATE X


Salir:
IF @error <> 0 BEGIN
	ROLLBACK TRANSACTION
END
ELSE BEGIN
	COMMIT TRANSACTION
END
GO
